package com.zeny.express.framework.config.impl;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent;
import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Zookeeper 目录下文件监听
 * 
 * @author zhuwei
 * @date 2013年8月30日 下午8:27:05
 */
public class PathChildrenCacheListenerImpl implements PathChildrenCacheListener {

	/**
	 * 日志
	 */
	private static final Logger LOGGER = LoggerFactory
			.getLogger(PathChildrenCacheListenerImpl.class);

	/** 
	 * 文件监听
	 * @author zhuwei
	 * @date 2013年8月30日 下午8:28:09
	 * @see org.apache.curator.framework.recipes.cache.PathChildrenCacheListener#childEvent(org.apache.curator.framework.CuratorFramework, org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent)
	 */
	@Override
	public void childEvent(CuratorFramework client, PathChildrenCacheEvent event)
			throws Exception {
		switch (event.getType()) {
		case CHILD_ADDED: {
			LOGGER.info("Node added: " + event.getData()
					+ new String(event.getData().getData()));
			break;
		}

		case CHILD_UPDATED: {
			LOGGER.info("Node added: " + event.getData()
					+ new String(event.getData().getData()));
			break;
		}

		case CHILD_REMOVED: {
			LOGGER.info("Node added: " + event.getData()
					+ new String(event.getData().getData()));
			break;
		}
		default:
			break;
		}
	}

}
